package com.zx.idc.backend.gui.sys;


import com.baomidou.mybatisplus.plugins.Page;
import com.zx.idc.backend.gui.common.BasicBaseApi;
import com.zx.idc.backend.gui.common.Result;
import com.zx.idc.backend.gui.common.base.BaseExcelApi;
import com.zx.idc.ds.common.constant.DelFlagConstant;
import com.zx.idc.ds.sys.entity.SysDomainCategory;
import com.zx.idc.ds.sys.service.ISysDomainCategoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * <p>
 * 域名类型管理 前端控制器
 * </p>
 *
 * @author chendong
 * @since 2019-04-17
 */
@RestController
@RequestMapping("/api/sysDomainCategory")
public class SysDomainCategoryController extends BasicBaseApi<ISysDomainCategoryService, SysDomainCategory> implements BaseExcelApi<ISysDomainCategoryService, SysDomainCategory> {

    @GetMapping("/query-page")
    @RequiresPermissions("system-configuration:sys-domain-category")
    public Result<Page<SysDomainCategory>> page(Page<SysDomainCategory> page, SysDomainCategory sysDomainCategory) {
        return success(service.pageByParam(page, sysDomainCategory));
    }

    /**
     * 根据id删除
     * 实际是更新delFlag字段 为 1：已删除,
     *
     * @param id
     * @return
     */
    @Override
    @RequiresPermissions("system-configuration:sys-domain-category")
    public Result<Boolean> delete(@PathVariable("id") Long id) {
        SysDomainCategory sysDomainCategory = new SysDomainCategory();
        sysDomainCategory.setId(Objects.toString(id));
        sysDomainCategory.setDelFlag(DelFlagConstant.DELETE);
        return success(service.updateById(sysDomainCategory));
    }

    @PostMapping("/update-or-add")
    @RequiresPermissions("system-configuration:sys-domain-category:edit")
    public Result<Boolean> updateOrAdd(@RequestBody SysDomainCategory sysDomainCategory) {
        sysDomainCategory.setDelFlag(DelFlagConstant.NORMAL);
        return success(service.insertOrUpdate(sysDomainCategory));
    }

}

